﻿@inject IJSRuntime JS
@using System.ComponentModel.DataAnnotations;
@using System.Text.Json;
@using Entitys.SSH
@using Microsoft.AspNetCore.SignalR.Client
@using Newtonsoft.Json
@inject MessageService _message
@inject HubConnection? hubConnecton
@inject ISessionStorageService sessionStorage
@*重命名弹窗*@
<Modal Title="请先登录SSh"
       Visible="@_visibleLoginSsh"
       OnOk="@LoginSshOk"
       OnCancel="()=>{_visibleLoginSsh=false;}">
       <span>
            主机名称：<Input Placeholder="主机名称" @bind-Value="@_sshUser.Host"  />
       </span>
       <span>
            端口：<Input Placeholder="端口" @bind-Value="@_sshUser.Port"  />
       </span>
       <span>
            账号：<Input Placeholder="账号" @bind-Value="@_sshUser.Username"  />
       </span>
       <span>
            密码：<InputPassword  Placeholder="密码" @bind-Value="@_sshUser.Password"  />
       </span>

</Modal>
@code {
    private bool _visibleLoginSsh = false;
    private SSHUser? _sshUser;
    private bool isLogin = false;
    protected override async void OnInitialized()
    {
        _sshUser=await sessionStorage.GetItemAsync<SSHUser>("sshUser");
        _visibleLoginSsh = _sshUser == null;
        _sshUser = new SSHUser();
        StateHasChanged();
    }
    public void ConnectSSH()
    {
        hubConnecton!.SendAsync("SSHConnectSend", JsonConvert.SerializeObject(_sshUser));
        hubConnecton!.On<bool>("hubConnectonMessage", (message) =>
        {
            isLogin = message;
        });
    }
    public void LoginSshOk()
    {
        if (string.IsNullOrEmpty(_sshUser?.Host))
        {
            _message.Warning("主机名不能为空");
            return;
        }

    }
}